package com.atguigu.spzx.manager.controller.product;

import com.atguigu.spzx.manager.service.product.ProductSpecService;
import com.atguigu.spzx.model.entity.product.ProductSpec;
import com.atguigu.spzx.model.vo.common.Result;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Mahone
 */
@RestController
@RequestMapping("/admin/product/productSpec")
public class ProductSpecController {

    @Autowired
    private ProductSpecService productSpecService;

    /**
     * 查询规格列表
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/getProductSpecPageList/{page}/{limit}")
    public Result getProductSpecPageList(@PathVariable("page") Integer pageNum,
                                         @PathVariable("limit") Integer pageSize){

        PageInfo<ProductSpec> productSpecPageInfo = productSpecService.getProductSpecPageList(pageNum,pageSize);
        return Result.ok(productSpecPageInfo);
    }


    /**
     * 规格管理添加功能
     * @param productSpec
     * @return
     */
    @PostMapping("/saveProductSpec")
    public Result saveProductSpec(@RequestBody ProductSpec productSpec) {
        productSpecService.insertProductSpec(productSpec);
        return Result.ok();
    }

    /**
     * 规格管理修改功能
     * @param productSpec
     * @return
     */
    @PostMapping("/updateProductSpecById")
    public Result updateProductSpecById(@RequestBody ProductSpec productSpec) {
        productSpecService.updateProductSpecById(productSpec);
        return Result.ok();
    }

    /**
     * 查询所有规格信息
     * @param
     * @return
     */
    @GetMapping("/findAllProductSpec")
    public Result findAllProductSpec() {
        List<ProductSpec> productSpecList = productSpecService.findAllProductSpec();
        return Result.ok(productSpecList);
    }



}
